package com.axend.sofa.adapter

import com.axend.lib_base.bean.SofaModelEntity
import com.axend.sofa.R
import com.axend.sofa.databinding.AdapterBleDeviceItemBinding
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import dagger.hilt.android.scopes.ActivityScoped
import javax.inject.Inject

@ActivityScoped
class BleModelAdapter @Inject constructor(): BaseQuickAdapter<SofaModelEntity, BaseDataBindingHolder<AdapterBleDeviceItemBinding>>(
    R.layout.adapter_ble_device_item) {

    init {
        addChildClickViewIds(R.id.cl_parent)
    }

    override fun convert(holder: BaseDataBindingHolder<AdapterBleDeviceItemBinding>, item: SofaModelEntity) {
        holder.dataBinding?.apply {
            tvDeviceName.text = item.modelName
            tvDeviceName.setTextColor(
                if (item.isSelect) {
                    context.getColor(com.axend.lib_base.R.color.colorPrimary)
                } else {
                    context.getColor(com.axend.lib_base.R.color.black)
                }
            )
            ivSelect.visibility = if (item.isSelect) {
                android.view.View.VISIBLE
            } else {
                android.view.View.GONE
            }
            if (data.size > 0 && holder.absoluteAdapterPosition == data.size - 1) {
                vLine.visibility = android.view.View.GONE
            } else {
                vLine.visibility = android.view.View.VISIBLE
            }
        }
    }
}